<template>
  <div class="flex flex-wrap font14 single-tags">
    <div :key="`single-tags-${i}`"
         :class="['item',__index===i?'active':'']"
         @click="onChange(i,item)"
         v-for="(item,i) of data">
      {{ item.label }}
    </div>
  </div>
</template>

<script lang="ts">
import {defineComponent} from 'vue'

export default defineComponent({
  name: "SingleTags",
  emits: [
    'onChange',
  ],
  props: {
    index: Number,
    data: {
      type: Array,
      default: () => []
    }
  },
  watch: {
    data: {
      immediate: true,
      handler(val: any[]) {
        if (this.__index === -1 && val.length > 0) {
          this.__index = this.index || 0;
        }
      },
    }
  },
  data() {
    return {
      __index: -1,
    }
  },
  methods: {
    onChange(index: number, item: any) {
      this.__index = index
      this.$emit('onChange', {item, index})
    }
  }
})
</script>

<style lang="less" scoped>
.single-tags {
  padding: 5px 0;

  .item {
    line-height: 30px;
    padding: 0 20px;
    border-radius: 20px;
    background-color: #ffffff;
    margin: 0 3px;

    &.active {
      background-color: #F6E3E2;
      //background-color: @primaryLightColor;
      //color: @primaryColor;
      color: #F9574F;
    }
  }
}
</style>